﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using 刘颜红销售项目管理.Business;
using 刘颜红销售项目管理.Business.DOM;
 
namespace 刘颜红销售项目管理
{
    public partial class DateRangeControl : UserControl
    {
        public DateRangeControl()
        {
            InitializeComponent();
        }

        private void chkStartDate_CheckedChanged(object sender, EventArgs e)
        {
            dtpStart.Enabled = chkStartDate.Checked;
        }

        private void chkEndDate_CheckedChanged(object sender, EventArgs e)
        {
            dtpEnd.Enabled = chkEndDate.Checked;
        }

        [System.ComponentModel.Browsable( false )]
        [System.ComponentModel.DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public DateTime StartDate
        {
            get
            {
                if (dtpStart.Enabled)
                    return dtpStart.Value;
                else
                    return DateTime.MinValue;
            }
            set
            {
                if (value == DateTime.MinValue)
                {
                    chkStartDate.Checked = false;
                }
                else
                {
                    chkStartDate.Checked = true;
                    dtpStart.Value = value;
                }
            }
        }

        [System.ComponentModel.Browsable(false)]
        [System.ComponentModel.DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden )]
        public DateTime EndDate
        {
            get
            {
                if (dtpEnd.Enabled)
                    return dtpEnd.Value;
                else
                    return DateTime.MaxValue;
            }
            set
            {
                if (value == DateTime.MaxValue)
                {
                    chkEndDate.Checked = false;
                }
                else
                {
                    chkEndDate.Checked = true;
                    dtpEnd.Value = value;
                }
            }
        }

        [System.ComponentModel.Browsable( false )]
        [System.ComponentModel.DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public object SelectedPeople
        {
            get
            {
                return txtPeople.EditValue;
            }
            set
            {
                txtPeople.EditValue = value;
            }
        }

        private void tvwPeople_DoubleClick(object sender, EventArgs e)
        {
            this.txtPeople.EditValue = tvwPeople.SelectedValue;
            this.txtPeople.ClosePopup();
        }

        private void DateRangeControl_Load(object sender, EventArgs e)
        {
            if (this.DesignMode)
                return;
            tvwPeople.RefreshView();
        }

        private void popupContainerEdit1_Popup(object sender, EventArgs e)
        {
            if (txtPeople.EditValue is Class人员基本信息)
            {
                TreeNode node = tvwPeople.Controler.GetNode(((Class人员基本信息)txtPeople.EditValue).所属单位);
                if (node != null)
                {
                    node.Expand();
                }
            }
            tvwPeople.SelectedValue = txtPeople.EditValue;
        }
    }
}
